<?php
	class User_model extends CI_Model
	{
		var $table = "db_users";
		public function __construct()
		{
			parent::__construct();
		}
		public function list_user()
		{
		  $this->db->where('id !=','1');
			return $this->db->get($this->table)->result();
		}
		public function create_users($data)
		{
			$data = array(
				'username' =>$data['username'],				
				'level'	   =>$data['level'],
                'password' =>$data['password'],	
                'active'   => $data['active'],
				'fullname' =>$data['fullname'],						
				'email'    =>$data['email'],			 
			);
			$this->db->set($data);
			if($this->db->insert($this->table)) return true; else false; 
		}
		public function update_users($id,$data)
		{
			$this->db->where('id',$id);
			$data = array(
				'username' =>$data['username'],				
				'level'	   =>$data['level'],
                'password' =>$data['password'],	
                'active'   => $data['active'],
				'fullname' =>$data['fullname'],						
				'email'    =>$data['email'],			 
			);
			$this->db->set($data);
			if($this->db->update($this->table)) return true; else false; 
		}
        function check_password($id,$pass)
        {
            $this->db->where('id',$id);
            $this->db->where('password',$pass);
            $q = $this->db->get($this->table);           
            if($q->num_rows() > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        function kiemtra_user($user)
        {            
            $this->db->where('username',$user);
            $q = $this->db->get($this->table);           
            if($q->num_rows() > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
		public function change_password($id,$password)
		{
			$this->db->where('id',$id);
			$data = array(
				'password'=>$password
			);
			$this->db->set($data);
			if($this->db->update($this->table)) return true; else false; 
		}
		public function check_login($username,$password)
		{
			$this->db->where('username',$username);
			$this->db->where('password',$password);
			
			$sql = $this->db->get($this->table);
			if($sql->num_rows() > 0)
			{
				return $sql;
			}
			else
			{
				return false;
			}
		}
        public function check_user($username)
		{
			$this->db->where('username',$username);		
			$sql = $this->db->get($this->table);
			if($sql->num_rows() > 0)
			{
				return $sql;
			}
			else
			{
				return false;
			}
		}
		public function get_id_members($id)
        {
            $this->db->where('id',$id);
            return $this->db->get($this->table)->row();
        }
        public function delete_members($id)
        {
            $this->db->where('id',$id);
            return $this->db->delete($this->table);
        }
        function change_group($id,$data)
        {
            $this->db->where('id',$id);
            $data = array(
                'level' => $data['level'],
            );
            $this->db->set($data);
            if($this->db->update($this->table)) return true; else return false;
        }
        function change_active($id,$data)
        {
            $this->db->where('id',$id);
            $data = array(
                'active' => $data['active'],
            );
            $this->db->set($data);
            if($this->db->update($this->table)) return true; else return false;
        }
       
        
	}
?>